import pyquery 
import sys,urllib
import datetime
import chardet
import MySQLdb  



base_url = 'http://community.topcoder.com'

html = open("Contests20111102_214157New.html", 'r').read()
p = pyquery.PyQuery(html)   
pollen_table = p('table.stat')
pollen_rows = pollen_table('tr')[2:]  #must make clear how htmlelement [] does
i = 2
while i <  len(pollen_rows) + 2:
    #print (pollen_table('tr').eq(i))
    row_fields = pollen_table('tr').eq(i)('td')
    print row_fields.eq(0).text()
#    for field in row_fields:
#        print field.text_content()
    i+=1

for i in range(2,len(pollen_rows)):
     fields = pollen_table('tr').eq(i)
     print len(fields('td')[:])
     for j in range(len(fields('td')[:])):
         if j != 1 and j != 2:
             print j,fields('td').eq(j).text()
#    pollen_source = fields[0].text_content()
#    pollen_value = fields[1].getchildren()[0].get('width')
#    print pollen_source.strip(), int(pollen_value)
